import { useDispatch, useSelector } from 'react-redux'
import { increment } from './store/actions/counter'
import { updateName } from './store/actions/user'

export default function User() {
  const user = useSelector((state) => state.user)
  const dispatch = useDispatch()
  // !#4 注意获取数据的方式变了
  const count = useSelector((state) => state.counter)
  return (
    <div>
      <p>name: {user.name}</p>
      <p>count: {count}</p>
      <button onClick={() => dispatch(updateName('李景亮'))}>
        update name
      </button>
      <button onClick={() => dispatch(increment(8))}>+8</button>
    </div>
  )
}
